#!/bin/bash

SVN_ROOT='https://ndeevor.googlecode.com/svn/trunk'
INSTALL_PATH=/home3/ndeevorc/www/test

##############################################################################################

echo "Please enter the SVN revision (leave blank for HEAD): "
read rev
if [ "z$rev" == "z" ]; then
  rev="HEAD"
fi

echo "Exporting source from subversion..."
TEMP_DIR=/tmp/ndeevor.$rev
if [ -d "$TEMP_DIR" ]; then
  rm -rf $TEMP_DIR
fi

svn export $SVN_ROOT $TEMP_DIR -r$rev

echo "Backing up existing files..."
if [ -d "$INSTALL_PATH" ]; then
  OLD_DIR=$INSTALL_PATH"_old"
  if [ -d "$OLD_DIR" ]; then
    rm -rf $OLD_DIR
  fi
  mv $INSTALL_PATH $OLD_DIR
fi

echo "Setting up..."
mv $TEMP_DIR $INSTALL_PATH
cd $INSTALL_PATH
chmod -R 777 log cache
rm -rf web/frontend_* web/backend_*
rm -rf install data
php symfony cc > /dev/null

echo ":: Setup is complete!"
